package cn.hinglo.permission.service;

import cn.hinglo.common.utils.SysCommonKit;
import cn.hinglo.permission.bean.Permission;
import cn.hinglo.permission.mapper.PermissionMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author HingLo
 * @createTime: 2019-04-29 12:18:27
 * @description: PermissionService 服务层
 */
@Slf4j
@Service
public class PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    /**
     * Permission列表
     *
     * @param page 页码
     * @param size 大小
     * @return Permission分页后集合
     */
    public Map<String, Object> listPermissionService(Integer page, Integer size) {

        Page pages = PageHelper.startPage(page, size);
        List<Permission> list = permissionMapper.selectAll();
        return SysCommonKit.pageKit(pages.getTotal(), list);
    }

    /**
     * 添加Permission
     *
     * @param permission Permission对象信息
     * @return 操作结果
     */
    public boolean addPermissionService(Permission permission) {
        // todo 其他操作
        return permissionMapper.insert(permission) > 0;
    }

    /**
     * 删除Permission对象
     *
     * @param id Permission对象的唯一ID
     * @return 操作结果
     */
    public boolean deletePermissionService(Integer id) {
        return id != null && permissionMapper.deleteByPrimaryKey(id) > 0;
    }
}

